package br.urca.model;

import java.io.Serializable;
import java.util.Date;

import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.EmbeddedId;
import javax.persistence.Entity;
import javax.persistence.JoinColumn;
import javax.persistence.JoinColumns;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.persistence.Transient;

/**
 *
 * @author Lucas
 */
@Entity
@Table(name = "BI_ITENS_RESERVA")
public class BiItensReserva implements Serializable {
	
    private static final long serialVersionUID = 1L;
    
    @EmbeddedId
    protected BiItensReservaPK biItensReservaPK;
    
    @Basic(optional = false)
    @Column(name = "LIBERADO")
    private Character liberado;

    @Column(name = "DATA_LIBERACAO")
    @Temporal(TemporalType.TIMESTAMP)
    private Date dataLiberacao;

    @JoinColumn(name = "COD_RESERVA", referencedColumnName = "COD_RESERVA", insertable = false, updatable = false)
    @ManyToOne(optional = false)
    private BiReservas biReservas;

    @JoinColumns({
        @JoinColumn(name = "COD_TIPO_MATERIAL", referencedColumnName = "COD_TIPO_MATERIAL"),
        @JoinColumn(name = "COD_NUMERO_MATERIAL", referencedColumnName = "COD_NUMERO_MATERIAL")})
    @ManyToOne
    private BiMateriais biMateriais;
    
    @JoinColumns({
        @JoinColumn(name = "COD_TIPO_COPIA", referencedColumnName = "COD_TIPO_MATERIAL"),
        @JoinColumn(name = "COD_NUMERO_COPIA", referencedColumnName = "COD_NUMERO_MATERIAL"),
        @JoinColumn(name = "COD_REGISTRO_COPIA", referencedColumnName = "COD_REGISTRO")})
    @ManyToOne
    private BiCopias biCopias;
    
    @Transient
    private String codReservaCript;

    public BiItensReserva() {
    }

    public BiItensReserva(BiItensReservaPK biItensReservaPK) {
        this.biItensReservaPK = biItensReservaPK;
    }

    public BiItensReserva(BiItensReservaPK biItensReservaPK, Character liberado) {
        this.biItensReservaPK = biItensReservaPK;
        this.liberado = liberado;
    }

    public BiItensReserva(String codReserva, short codItem) {
        this.biItensReservaPK = new BiItensReservaPK(codReserva, codItem);
    }

    public BiItensReservaPK getBiItensReservaPK() {
        return biItensReservaPK;
    }

    public String getCodReservaCript() {
		return codReservaCript;
	}

	public void setCodReservaCript(String codReservaCript) {
		this.codReservaCript = codReservaCript;
	}

	public void setBiItensReservaPK(BiItensReservaPK biItensReservaPK) {
        this.biItensReservaPK = biItensReservaPK;
    }

    public Character getLiberado() {
        return liberado;
    }

    public void setLiberado(Character liberado) {
        this.liberado = liberado;
    }

    public Date getDataLiberacao() {
        return dataLiberacao;
    }

    public void setDataLiberacao(Date dataLiberacao) {
        this.dataLiberacao = dataLiberacao;
    }

    public BiReservas getBiReservas() {
        return biReservas;
    }

    public void setBiReservas(BiReservas biReservas) {
        this.biReservas = biReservas;
    }

    public BiMateriais getBiMateriais() {
        return biMateriais;
    }

    public void setBiMateriais(BiMateriais biMateriais) {
        this.biMateriais = biMateriais;
    }

    public BiCopias getBiCopias() {
        return biCopias;
    }

    public void setBiCopias(BiCopias biCopias) {
        this.biCopias = biCopias;
    }

    @Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime
				* result
				+ ((biItensReservaPK == null) ? 0 : biItensReservaPK.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		BiItensReserva other = (BiItensReserva) obj;
		if (biItensReservaPK == null) {
			if (other.biItensReservaPK != null)
				return false;
		} else if (!biItensReservaPK.equals(other.biItensReservaPK))
			return false;
		return true;
	}

	@Override
    public String toString() {
        return getDescSituacao(this.getLiberado());//"model.BiItensReserva[ biItensReservaPK=" + biItensReservaPK + " ]";
    }
	
	private String getDescSituacao(Character situacao) {
		switch (situacao) {
		case 'F': return "Pendente";
		case 'T': return "Liberado";
		default: return "";
		}
	}
    
}
